package com.wibo.account;

import com.wibo.common.Constants;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;

public class WiboOthersActivity extends Activity implements OnClickListener {
	private CUserManager mUserManager = null;
	private LinearLayout mHotRepostLayout;
	private LinearLayout mHotCommentsLayout;
	private LinearLayout mHotTrendsLayout;
	private LinearLayout mPublicWeiboLayout;

	private void setContentViewSkin() {
		int skin = mUserManager.getMySkin();
		switch (skin) {
		case 0:
			setContentView(R.layout.wibo_other);
			break;
		case 1:
			setContentView(R.layout.wibo_other_2);
			break;
		default:
			setContentView(R.layout.wibo_other);
			break;
		}
	}
	
	/* (non-Javadoc)
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		mUserManager = CUserManager.getInstance(this);
		
		setContentViewSkin();
		//setContentView(R.layout.wibo_other_2);
		
		mHotRepostLayout = (LinearLayout) findViewById(R.id.HotRepost);
		mHotCommentsLayout = (LinearLayout) findViewById(R.id.HotComments);
		mHotTrendsLayout = (LinearLayout) findViewById(R.id.HotTrends);
		mPublicWeiboLayout = (LinearLayout) findViewById(R.id.PublicWeibo);
		mHotRepostLayout.setClickable(true);
		mHotCommentsLayout.setClickable(true);
		mHotTrendsLayout.setClickable(true);
		mPublicWeiboLayout.setClickable(true);
		mHotRepostLayout.setOnClickListener(this);
		mHotCommentsLayout.setOnClickListener(this);
		mHotTrendsLayout.setOnClickListener(this);
		mPublicWeiboLayout.setOnClickListener(this);
	}

	/* (non-Javadoc)
	 * @see android.app.Activity#onDestroy()
	 */
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.HotRepost:
			Intent intent = new Intent(WiboOthersActivity.this, WeiboListActivity.class);
    		Bundle bundle = new Bundle();
    		bundle.putInt("weiboType", WeiboListActivity.HOT_REPOST);
			intent.putExtras(bundle);
			startActivity(intent);
			break;
		case R.id.HotComments:
			intent = new Intent(WiboOthersActivity.this, WeiboListActivity.class);
    		bundle = new Bundle();
    		bundle.putInt("weiboType", WeiboListActivity.HOT_COMMENTS);
			intent.putExtras(bundle);
			startActivity(intent);
			break;
		case R.id.HotTrends:
			intent = new Intent(WiboOthersActivity.this, WeiboListActivity.class);
    		bundle = new Bundle();
    		bundle.putInt("weiboType", WeiboListActivity.HOT_TRENDS);
			intent.putExtras(bundle);
			startActivity(intent);
			break;
		case R.id.PublicWeibo:
			break;
		}
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		
		super.onResume();
		SharedPreferences lastPreferences = getSharedPreferences(Constants.PREFERENCE_NAME, 3);
        SharedPreferences.Editor editor = lastPreferences.edit();
        editor.putInt(Constants.PREFERENCE_RECORD, 3);
        editor.commit();
	}
	
	@Override
	public void onBackPressed() {
        Activity parent = getParent();
        if(parent != null) {
        	SharedPreferences lastPreferences = getSharedPreferences(Constants.PREFERENCE_NAME, 3);
            SharedPreferences.Editor editor = lastPreferences.edit();
            editor.putInt(Constants.PREFERENCE_RECORD, 3);
            editor.commit();
            
            parent.onBackPressed();
        } else {       	
        	SharedPreferences lastPreferences = getSharedPreferences(Constants.PREFERENCE_NAME, 3);
            SharedPreferences.Editor editor = lastPreferences.edit();
            editor.putInt(Constants.PREFERENCE_RECORD, 3);
            editor.commit();
            
            super.onBackPressed();
        }
	}

	@Override
	protected void onPause() {
		Activity parent = getParent();
        if(parent != null) {
        	SharedPreferences lastPreferences = getSharedPreferences(Constants.PREFERENCE_NAME, 3);
            SharedPreferences.Editor editor = lastPreferences.edit();
            editor.putInt(Constants.PREFERENCE_RECORD, 3);
            editor.commit();
            
        } else {       	
        	SharedPreferences lastPreferences = getSharedPreferences(Constants.PREFERENCE_NAME, 3);
            SharedPreferences.Editor editor = lastPreferences.edit();
            editor.putInt(Constants.PREFERENCE_RECORD, 3);
            editor.commit();
            
        }
		super.onPause();
	}
}
